package com.example.demotest.pojo;

import org.aspectj.bridge.IMessage;
import org.springframework.http.HttpStatus;

import java.net.http.HttpClient;

public class ResponseMessage<T> {
    private Integer code;
    private String message;
    private T data;
    private String token;

    public void setToken(String token) {
        this.token = token;
    }

    public ResponseMessage(Integer code, String message, T data, String token){
        this.code = code;
        this.message = message;
        this.data = data;
        this.token = token;
    }

    public ResponseMessage(Integer code ,String message,T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 请求成功 - 带数据
    public static <T> ResponseMessage<T> success(T data){
        return new ResponseMessage<>(HttpStatus.OK.value(), "success!", data, null);
    }

    // 请求成功 - 不带数据
    public static <T> ResponseMessage<T> success(){
        return new ResponseMessage<>(HttpStatus.OK.value(), "success!", null, null);
    }

    // 请求成功 - 自定义message
    public static <T> ResponseMessage<T> success(String message,T data){
        return new ResponseMessage<>(HttpStatus.OK.value(),message,data);
    }

    public String getToken() {
        return token;
    }

    // 请求失败 - 带错误码
    public static <T> ResponseMessage<T> error(int code, String message) {
        return new ResponseMessage<>(code, message, null, null);
    }

    // 请求失败 - 默认500错误码
    public static <T> ResponseMessage<T> error(String message) {
        return new ResponseMessage<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, null, null);
    }

    // 添加返回 token 的成功方法
    public static <T> ResponseMessage<T> successWithToken(T data, String token) {
        return new ResponseMessage<>(HttpStatus.OK.value(), "成功", data, token);
    }




    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}